﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Xml.Linq;

namespace HouseAgencySite.Utils
{
    public abstract class EmailSenderBase
    {
        public XDocument Document { get; protected set; }

        public string SetUpFileName = AppDomain.CurrentDomain.BaseDirectory + "/bin/SetUp.xml";// "I:\\2016\\HouseAgencySite\\HouseAgencySite\\Utils\\SetUp.xml";
        public const string RootElementName = "SetUp";

       
        public void SetUpXmlExists()
        {
            if (!File.Exists(SetUpFileName))
            {
                throw new FileNotFoundException(
                    "You must provide an SetUp.xml file to run these unit tests");
            }
        }

        public void SetUp()
        {


            try
            {
                Document = XDocument.Load(SetUpFileName);
                var root = Document.Element(RootElementName);

                // Do validation
                if (root == null)
                {
                    throw new SetUpException("SetUp element could not be found from SetUp.xml");
                }

                // Do parsing
                ParseSetUpXml(root);

            }
            catch (Exception ex)
            {
                throw new SetUpException("Test settings could not be parsed from SetUp.xml", ex);
            }
        }

        protected abstract void ParseSetUpXml(XElement element);

    }
}